package com.smart.controller.sys;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smart.controller.BaseController;
import com.smart.entity.SiteInspection;
import com.smart.entity.SysInspectionRecord;
import com.smart.service.InspectionRecordService;
import com.smart.service.SiteInspectionService;
import com.smart.util.DateUtil;
import com.smart.util.ExportExcelUtils;
import com.smart.util.Messages;
import com.smart.vo.sys.SiteInspectionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lgb、afnhai
 * @date 2020年6月23日 上午9:19:31
 * Copyright (C) 深圳工勘科技
 * @说明: 后台端车辆巡检
 **/
@RestController
@RequestMapping("/sys/car_inspection")
@Api(value="carInspection",tags="智慧工地-车辆巡检管理")
public class CarInspectionController extends BaseController{

    @Resource
    private InspectionRecordService inspectionRecordService;

//	@ApiOperation(value="sys获取工地车辆巡检分页",notes="sys获取工地车辆巡检分页")
//	@GetMapping(value="/page")
//	public Messages<IPage<SysInspectionRecord>> page(String createTime,
//													 @RequestParam(name="pageNum")Integer pageNum,
//													 @RequestParam(name="pageSize")Integer pageSize){
//		IPage<SysInspectionRecord> page=
//				inspectionRecordService.findPage(pageNum,
//						pageSize,createTime);
//		return Messages.success(page);
//	}

    @ApiOperation(value="sys获取工地车辆巡检详情",notes="sys获取工地车辆巡检详情")
    @GetMapping(value="/detail/{id}")
    public Messages<SysInspectionRecord> detail(@PathVariable Integer id){
        SysInspectionRecord sInr = inspectionRecordService.getById(id);
        return Messages.success(sInr);
    }

    @ApiOperation(value="sys获取工地巡检分页",notes="sys获取工地巡检分页")
    @GetMapping(value="/page")
    public Messages<IPage<SysInspectionRecord>> page(String carNo,String carType,
                                                     String createTime_start,String createTime_end,
                                                     @RequestParam(name="pageNum")Integer pageNum,
                                                     @RequestParam(name="pageSize")Integer pageSize){
        IPage<SysInspectionRecord> page=
                inspectionRecordService.sysFindPage(carNo,carType,
                        createTime_start,createTime_end,pageNum,pageSize);
        return Messages.success(page);
    }

    /**
     * @param res
     * @return 导出所有数据
     **/
//	@GetMapping(value="/export_excel")
//    public void exportExcel(HttpServletResponse res){
//		List<SysInspectionRecord> list = inspectionRecordService.list();
//		List<SiteInspectionVo> voList = new ArrayList<>();
//		if(!list.isEmpty()){
//			for(SysInspectionRecord ins : list){
//				SiteInspectionVo vo = new SiteInspectionVo();
//				vo.setCreateTime(DateUtil.formatLongStr(ins.getCreateTime()));
//				vo.setInspectionDate(ins.getInspectionDate());
//				vo.setPosition(ins.getPosition());
//				vo.setRemark(ins.getRemark());
//				vo.setResult(ins.getResult()==0?"异常":"正常");
//				vo.setSiteName(ins.getSiteName());
//				vo.setSubmitName(ins.getSubmitName());
//				voList.add(vo);
//			}
//		}
//		String title = "工地巡检记录.xlsx";
//        String[] rowName={"提交时间","所属日期","所属工地","巡检位置","巡检结果","巡检内容","提交者"};
//        List<Object> datalist=new ArrayList<>(1);
//        datalist.addAll(voList);
//        ExportExcelUtils.exportExcel(res,title,rowName,datalist);
//	}

}